/*
Write a program to see what happens if we try to longjmp() into a function that has
already returned.
 */

// result. segmentation fault

#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>

static jmp_buf env;

static void f2(void);

static void
f1(int argc)
{
  f2();
  if (argc == 2)
    {
      puts("ops, argument given!");
      longjmp(env, 1);
    }
}

static void
f2(void)
{
  puts("time, to do something");
  if (setjmp(env) == 0)
    {
      puts("setjmp executed");
    }
  else
    {
      puts("recover");
    }
}

int
main(int argc, char *argv[])
{
  f1(argc);
  return EXIT_SUCCESS;
}
